home *** CD-ROM | disk | FTP | other *** search
- //Abnormal include files for an atypical Windows program... aCk!
- #include <windows.h>
- #include <mmsystem.h>
- #include <stdio.h>
-
- extern "C"
- {
- #include "wxlib.h"
- #include "xcircle.h"
- #include "xpal.h"
- #include "xrect.h"
- }
-
- #define A asm
- #define A32 __emit__(0x67); asm
-
- //This is the address of the screen selector.
- extern WORD _near _A000H;
-
- //The undocumented Death() and Resurrection() Functions. Oooo...
- extern "C"
- {
- void FAR PASCAL Death(HDC dc);
- void FAR PASCAL Resurrection(HDC dc, WORD w1, WORD w2, WORD w3, WORD w4, WORD w5, WORD w6);
- }
-
- typedef void *Pvoid;
- typedef char *Pchar;
-
- typedef struct
- {
- int x, y;
- int r;
- int dx, dy;
- int dr;
- } TPoint;
-
- unsigned char bluepal[16*3] =
- {
- 0, 0, 4,
- 0, 0, 8,
- 0, 0, 12,
- 0, 0, 16,
- 0, 0, 20,
- 0, 0, 24,
- 0, 0, 28,
- 0, 0, 32,
- 0, 0, 36,
- 0, 0, 40,
- 0, 0, 44,
- 0, 0, 48,
- 0, 0, 52,
- 0, 0, 56,
- 0, 0, 60,
- 0, 0, 63
- };
-
- TPoint cir[16];
- HWND hwnd;
-
- //Check if a key is waiting in Windows message queue.
- int KeyHit()
- {
- MSG msg;
-
- while (PeekMessage(&msg, hwnd, 0, 0x7FFF, PM_NOREMOVE))
- {
- if (msg.message == WM_KEYDOWN)
- return TRUE;
- GetMessage(&msg, hwnd, 0, 0x7FFF);
- }
- return FALSE;
- }
-
- //Get a key from Windows message queue
- int GetChar()
- {
- MSG msg;
-
- do
- {
- GetMessage(&msg, hwnd, 0, 0x7FFF);
- } while (msg.message != WM_KEYDOWN);
- return msg.wParam;
- }
-
- //Kill the GDI, and initialize mode x.
- void gfxmode(WORD xmode, WORD width)
- {
- ShowCursor(FALSE);
- HDC dc = GetDC(NULL);
- Death(dc);
- ReleaseDC(NULL, dc);
-
- //This is in XLib, and we now set it to the correct selector
- SCREEN_SEG = (WORD)&_A000H;
-
- x_set_mode(xmode, width);
- }
-
- //Bring the GDI back to life!
- void winmode()
- {
- x_text_mode();
-
- HDC dc = GetDC(NULL);
- Resurrection(dc, 0, 0, 0, 0, 0, 0);
- ReleaseDC(NULL, dc);
- RedrawWindow(GetDesktopWindow(), NULL, NULL,
- RDW_ERASE | RDW_FRAME | RDW_INVALIDATE |
- RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN);
- ShowCursor(TRUE);
- }
-
- //A generic memory allocation routine for Windows
- Pvoid AllocMem(DWORD size)
- {
- HGLOBAL h = GlobalAlloc(GPTR, size);
- GlobalFix(h);
- GlobalPageLock(h);
- return GlobalLock(h);
- }
-
- //A generic memory deletion routine for Windows
- void FreeMem(Pvoid p)
- {
- HGLOBAL h = (HGLOBAL)LOWORD(GlobalHandle(HIWORD((DWORD)p)));
- GlobalUnlock(h);
- GlobalPageUnlock(h);
- GlobalUnfix(h);
- GlobalFree(h);
- }
-
- void RunIt()
- {
- BOOL done = FALSE;
- int ch;
- int i;
-
- x_put_pal_raw(bluepal, 16, 16);
-
- cir[ 0].x = 120; cir[ 0].y = 60; cir[ 0].r = 20;
- cir[ 1].x = 125; cir[ 1].y = 65; cir[ 1].r = 22;
- cir[ 2].x = 130; cir[ 2].y = 70; cir[ 2].r = 24;
- cir[ 3].x = 135; cir[ 3].y = 75; cir[ 3].r = 26;
- cir[ 4].x = 140; cir[ 4].y = 80; cir[ 4].r = 28;
- cir[ 5].x = 145; cir[ 5].y = 85; cir[ 5].r = 30;
- cir[ 6].x = 150; cir[ 6].y = 90; cir[ 6].r = 32;
- cir[ 7].x = 155; cir[ 7].y = 95; cir[ 7].r = 34;
- cir[ 8].x = 160; cir[ 8].y = 100; cir[ 8].r = 36;
- cir[ 9].x = 165; cir[ 9].y = 105; cir[ 9].r = 38;
- cir[10].x = 170; cir[10].y = 110; cir[10].r = 40;
- cir[11].x = 175; cir[11].y = 115; cir[11].r = 42;
- cir[12].x = 180; cir[12].y = 120; cir[12].r = 44;
- cir[13].x = 185; cir[13].y = 125; cir[13].r = 46;
- cir[14].x = 190; cir[14].y = 130; cir[14].r = 48;
- cir[15].x = 195; cir[15].y = 135; cir[15].r = 50;
-
- for (i = 0; i < 16; i++)
- {
- cir[i].dr = -1;
- cir[i].dx = 1;
- cir[i].dy = 1;
- }
-
- sndPlaySound("BEAT.WAV", SND_ASYNC | SND_LOOP);
-
- while (!done)
- {
- if (KeyHit())
- {
- ch = GetChar();
- switch (ch)
- {
- case VK_LEFT: // left
- {
- break;
- }
- case VK_RIGHT: // right
- {
- break;
- }
- case VK_UP: // forward
- {
- break;
- }
- case VK_DOWN: // down
- {
- break;
- }
- case '\x1B':
- {
- done = TRUE;
- break;
- }
- }
- }
- for (i = 0; i < 16; i++)
- {
- x_circle(cir[i].x, cir[i].y, cir[i].r, i+16, HiddenPageOffs);
- cir[i].x += cir[i].dx;
- cir[i].y += cir[i].dy;
- cir[i].r += cir[i].dr;
- if (cir[i].r > 50 || cir[i].r < 10)
- cir[i].dr = -cir[i].dr;
- if (cir[i].x + 50 > 319 || cir[i].x - 50 < 1)
- cir[i].dx = -cir[i].dx;
- if (cir[i].y + 50 > 199 || cir[i].y - 50 < 1)
- cir[i].dy = -cir[i].dy;
- }
- x_page_flip(0,0);
- x_rect_fill(0, 0, 320, 240, HiddenPageOffs, 0);
- }
- sndPlaySound(NULL, NULL);
- }
-
- int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int)
- {
- _InitEasyWin();
- hwnd = GetFocus();
-
- //Kill GDI, initialize mode x.
- gfxmode(X_MODE_320x240, 0);
- x_set_doublebuffer(200);
-
- //Run the program's main loop
- RunIt();
-
- DestroyWindow(hwnd);
-
- //Back to text mode.
- winmode();
-
- return 0;
- }
-
-